/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.kz.shange.service;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import org.kz.shange.common.KzResp;
import org.kz.shange.imgSvc.BCSSvc;
import org.kz.shange.models.Fun;
import org.kz.shange.models.FunMeta;
import org.kz.shange.models.IWosahDao;

/**
 *
 * @author Administrator
 */
@Path("/wosahService")
@Consumes("application/vnd.customer+json; charset=UTF-8")
@Produces("application/vnd.customer+json; charset=UTF-8")
public class WosahService {

    private IWosahDao wosahDao;
    private final int perLoadFunSize; //每加载一组文章的数量

    public WosahService() {
        this.perLoadFunSize = 20;
    }

    @POST
    @Path("/saveFun/")
    public KzResp<Fun> saveFun(FunMeta fm) {

        return this.wosahDao.saveFun(fm);

    }
    
    public KzResp<String> savePicthure(String url){
        BCSSvc svc=new BCSSvc();
        try {
            svc.uploadMediaByUrl(url);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(WosahService.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(WosahService.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    @GET
    @Path("/loadReaderInterestFuns/{uid}/{from}/")
    public KzResp<List<Fun>> loadReaderInterestFuns(@PathParam("uid") String uid, @PathParam("from") int from) {
        return this.wosahDao.loadReaderInterestFuns(uid, from, this.perLoadFunSize);
    }

//<editor-fold defaultstate="collapsed" desc="property">
    
    
    public IWosahDao getWosahDao() {
        return wosahDao;
    }
    
    public void setWosahDao(IWosahDao wosahDao) {
        this.wosahDao = wosahDao;
    }
//</editor-fold>
}
